
//自定义组件--倒计时闹钟
module components {
	export class TimeOut extends eui.Component {
		public constructor() {
			super();
			this.skinName = "resource/ui/components/TimeOutSkin.exml";
			// this.addEventListener(egret.Event.ADDED, this.init, this);
			this.addEventListener(egret.Event.REMOVED, this.destroy, this);
		}
		public timeText: eui.BitmapLabel;

		private time: number = 0;
		private timeId: number;

		public init(time: number = 0, doudong: boolean = false) {
			this.visible = true;
			egret.clearInterval(this.timeId);
			this.time = time;
			this.timeText.text = this.time + "";
			this.timeId = egret.setInterval(() => {
				try {
					this.time--;
					if (this.time < 5 && doudong) {
						EffectUtils.shakeObj(this.timeText);
					}
					if (this.time < 0) {
						this.destroy();
						return;
					}
					this.timeText.text = this.time + "";
				} catch (e) {
					egret.clearInterval(this.timeId);
				}
			}, this, 1000);
		}
		public destroy() {
			egret.clearInterval(this.timeId);
			this.visible = false;
		}
	}
}